# -*- coding: utf-8 -*-
#!/usr/bin/env python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rospy
from rosgraph_msgs.msg import Clock

uav_id = $id

def publish_time():
    rospy.init_node('time_publisher', anonymous=True)
    clock_pub = rospy.Publisher('/time_{}'.format(uav_id), Clock, queue_size=10)
    rate = rospy.Rate(30)  # 发布频率为 30 Hz

    while not rospy.is_shutdown():
        # 获取当前 ROS 时间
        clock_msg = Clock()
        current_time = rospy.Time.now()

        # 将时间转换为秒数（精确到小数点后）
        clock_msg.clock = current_time

        # 打印秒数的小数部分（可选）
        #rospy.loginfo("Current time (seconds with decimal): {:.6f}".format(current_time.to_sec()))

        # 发布当前时间
        clock_pub.publish(clock_msg)

        rate.sleep()

if __name__ == '__main__':
    try:
        publish_time()
    except rospy.ROSInterruptException:
        pass
